---@class UIHeroRankPreview
UIHeroRankPreview = Class("UIHeroRankPreview")
function UIHeroRankPreview:ctor()

end
---@param obj GComponent
function UIHeroRankPreview:Bind(obj,closeCallback)
    self.starList = obj:GetChild("starList")
    self.unlockTitle = obj:GetChild("unlockTitle")
    self.upTitle = obj:GetChild("upTitle")
    self.skillItem = {}
    self.upSkillItem = {}
    for k = 1,4 do
        local skill = obj:GetChild("skill"..k)
        self.skillItem[k] = {
            go = skill,
            icon = skill:GetChild("mask"):GetChild("icon"),
            txt = skill:GetChild("title")
        }
        skill = obj:GetChild("upSkill"..k)
        self.upSkillItem[k] = {
            go = skill,
            icon = skill:GetChild("mask"):GetChild("icon"),
            txt = skill:GetChild("title")
        }
    end
    self.attrList = {}
    for i = 0,2 do
        local attr = obj:GetChild("attr"..i)
        self.attrList[i+1] = {
            num = attr:GetChild("num"),
            upNum = attr:GetChild("upNum")
        }
    end
    self.btnBack = obj:GetChild("btnBack")
    self.btnBack.onClick:Clear()
    self.btnBack.onClick:Add(self.ClickBack,self)
    self.closeCallback = closeCallback
end
function UIHeroRankPreview:RefreshAttr(data,RankUpID)
    local curHeroAttribute=data["allAttribute"][1]
    local baseData=clone(data)
    logicMgr.HeroManager.processHeroBaseAttr(baseData,data.level,RankUpID)
    self.attrList[1].num.text = curHeroAttribute[EnumConst.FighterAttributeEnum.HP];
    self.attrList[2].num.text = curHeroAttribute[EnumConst.FighterAttributeEnum.ATK];
    self.attrList[3].num.text = curHeroAttribute[EnumConst.FighterAttributeEnum.DEF];
    --txt_att_Fight.text = curHeroData["power"]
    local attbase=baseData.allAttribute[EnumConst.AttributeTypeEnum.BASE]
    self.attrList[1].upNum.text = attbase[EnumConst.FighterAttributeEnum.HP];
    self.attrList[2].upNum.text =attbase[EnumConst.FighterAttributeEnum.ATK];
    self.attrList[3].upNum.text =attbase[EnumConst.FighterAttributeEnum.DEF];
end
function UIHeroRankPreview:RefreshStar(star)
    local starcount =math.floor(star);
    for i = 1, self.starList.numItems do
        local child = self.starList:GetChildAt(i-1)
        child:GetController("cstar").selectedIndex = i<= starcount and 1 or 0
    end
    if(star-starcount>0)then
        local child = self.starList:GetChildAt(starcount)
        child:GetController("cstar").selectedIndex = 2
    end
end
function UIHeroRankPreview:RefreshSkill(sillUpInfo)
    for k,v in pairs(self.skillItem) do
        v.go.visible = false
        self.upSkillItem[k].go.visible = false
    end
    local show = #sillUpInfo > 0
    self.upTitle.visible = show
    self.unlockTitle.visible = show
    for i = 1, #sillUpInfo do
        local thisSkill=sillUpInfo[i]
        local tb
        if(thisSkill.level==1)then
            tb = self.skillItem[i]
        else
            tb = self.upSkillItem[i]
        end
        local tempSkillinfo=logicMgr.SkillManager.getSkillInfoConfig(thisSkill.id);--"12002"
        tb.go.visible = true
        tb.icon.url = EnumConst.AtlasPath.SkillAtlas..tempSkillinfo.f_SkillIcon
        tb.txt.text = getLanguage(tempSkillinfo.f_SkillName)..thisSkill.level
    end
end
function UIHeroRankPreview:OnDestroy()
    --need release component
end
function UIHeroRankPreview:ClickBack()
    if self.closeCallback then
        self.closeCallback()
    end
end
return UIHeroRankPreview
